 {{include file="../tools/jquery_validator2.htm"}}

<div class="userbox">
  <h2>店铺青币管理</h2>
  <form  id="gold" method="post">
    <div class="left left0">
      <table class="jifentable">
        <tr>
          <td colspan="4" class="nameorange" >我想要：</td>
        </tr>
        <tr>
          <td class="colororange">将青币分配给店员</td>
          <td>
           <select name="user_id">
           <option value="">选择店员</option>
            <option value="{{$cat.mag.user_id}}">{{$cat.mag.user_name}}</option>
          	{{foreach from=$cat.members item=list key=key}}
            <option value="{{$list.user_id}}">{{$list.user_name}}</option>
            {{/foreach}}
            </select>
            <td>
            <input type="text" class="textjf" name="amount"/>
            <span>青币</span>
            <input   type="text" class="beizhu" name="comment" value="备注" onclick="if(this.value=='备注') this.value=''">
            <input type="button" value="确定"  class="btn_jq" style="float:none" onclick="setGold()"/>
            </td>
          </td>
          
        </tr>
        <tr>
          <td  class="colororange">用青币兑换道具</td>
          <td  colspan="2"> <input type="button" value="进入商城"  class="btn_jq" style="float:none"/></td>
        </tr>
         <tr>
          <td  class="colororange">用青币举报抄袭</td>
          <td  colspan="2"> <input type="button" value="进入商城"  class="btn_jq" style="float:none"/></td>
        </tr>
        </table>
        <table class="jifentablet">
        <tr>
          <td colspan="3"  class="bordernone">查看明细</td>
        </tr>
        {{foreach from=$gold_log item=list key=key}}
         <tr {{if $key%2==0}}class="odd"{{/if}}>
          <td class="width1"><small>{{$list.add_time}}</small></td>
          <td class="width2">{{$comment=$list.comment}}
           {{if $g==$list.buyer}}
			  {{$comment|replace:"收入":"支出"}}  
          {{else}}
          	  {{$comment|replace:"支出":"收入"}}  
          {{/if}} 
          </td>
          <td class="width3 bordernone"> <strong class="greent">
          {{if $list.amount>0}}
          {{if $g==$list.buyer}}-{{else}}+{{/if}}
          {{/if}}
           {{$list.amount}}</strong></td>
        </tr>
        {{/foreach}}
       
      </table>
      <div class="icobtn">
      	
       
      </div>
    </div>
  </form>
 
 
 <div class="right">
    <p class="information">目前可用青币:<span class="colorred">{{$cat.gold}}</span></p>
  
  </div>
  <!--right end--> 
    {{include file="../pager.htm"}}
</div>
<script>
	

//店铺内发送金币给店员
 function setGold(){
	 var data = new Object;
	 var cat_gold = '{{$cat.gold}}';
	 data.buyer = 'c_{{$cat.cat_id}}';
	 data.geter = 'u_'+$("select[name=user_id]").val();
	
	 data.type = '2';
	 data.amount = $("input[name=amount]").val();
	 var comment= $("input[name=comment]").val();
	 if(data.geter=='')
	 {
		alert("请选择店员!");
		return false;	 
	 }
	 if((cat_gold-data.amount >=0) && chk.isInteger(data.amount))
	 {
		 var geter_text = $("select[name=user_id]").find("option:selected").text();
		 data.comment = (comment =='备注') ? '{{$cat.cat_name}} 分配给 '+geter_text+' '+data.amount+' 青币 操作人:{{$session.user_info.user_name}}' : comment;
		 var da = "act=send_gold&data="+$.toJSON(data);
		 Main.AJAX(sep+"/ajax.php",da,setGoldRes)
	 }
	 else
	 {
		alert("您输入的金额不正确，请重新输入!");	 	 
	 }
  }
  
 function setGoldRes(res){
	if(res=='1')
	{
		alert('操作成功!');
		location.href = location.href;	
	}
	else
	{
		alert("操作失败，请重试");
		location.href = location.href;	
	}
 }
  
 
</script>